<?php

namespace app\common\repository\userStatistics;

use think\Db;
use app\common\model\user\User as UserModel;
use app\common\model\user\UserStatistics as UserStatisticsModel;

class U
{
    public function __construct(
        UserModel $userModel,
        UserStatisticsModel $userStatisticsModel
    )
    {
        $this->userModel = $userModel;
        $this->userStatisticsModel = $userStatisticsModel;
    }

    public function doUserViewByArticleId($id)
    {
        $user =UserModel::hasWhere('article', ['id' => $id])->find();
        $doViewSql = '
            UPDATE
                user_statistics
            SET
                view_count = view_count + 1
            WHERE
                user_id = :user_id
            ';
        Db::execute($doViewSql, ['user_id' => $user->id]);
    }

    public function doUserArticleByArticleId($id)
    {
        $user =UserModel::hasWhere('article', ['id' => $id])->find();
        $doArticleSql = '
            UPDATE
                user_statistics
            SET
                article_count = article_count + 1
            WHERE
                user_id = :user_id
            ';
        Db::execute($doArticleSql, ['user_id' => $user->id]);
    }
}
